<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="账号、名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          value-format = "yyyy-MM-dd HH:mm:ss"
          v-model="dataForm.time"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('generator:shoppingbalancelog:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <!-- <el-table-column
        prop="balanceId"
        header-align="center"
        align="center"
        label="余额变动Id">
      </el-table-column> -->
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="余额变动人账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="余额变动人名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="用户类型">
        <template slot-scope="scope">
          <el-tag>{{scope.row.userType === 1 ? '运营商' : (scope.row.userType === 2 ? '联盟店' : (scope.row.userType === 3 ? '普通消费者' : (scope.row.userType === 4 ? 'VIP会员' : (scope.row.userType === 5 ? '普通联盟店' : (scope.row.userType === 6 ? '高级联盟店' : (scope.row.userType === 7 ? '城市合伙人' : (scope.row.userType === 8 ? '联盟店城市合伙人' : '')))))))}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="changeType"
        header-align="center"
        align="center"
        label="余额变动类型">
        <template slot-scope="scope">
          <el-tag>{{scope.row.changeType === 1 ? '商家线上订单收益' : (scope.row.changeType === 2 ? '商家线下订单收益' : (scope.row.changeType === 3 ? '首单3块钱' : (scope.row.changeType === 4 ? '邀请奖励' : (scope.row.changeType === 5 ? '福利分佣' : (scope.row.changeType === 6 ? '店铺利润分佣' :
            (scope.row.changeType === 7 ? '退单' : (scope.row.changeType === 8 ? '用户推广佣金提现' : (scope.row.changeType === 9 ? '店铺订单金额提现' : (scope.row.changeType === 10 ? '推广短信消费' : (scope.row.changeType === 11 ? '推广充值返现' : (scope.row.changeType === 12 ? '推广订单交易返现' : '后台佣金调整')))))))))))}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="balanceType"
        header-align="center"
        align="center"
        label="余额类型">
        <template slot-scope="scope">
          <el-tag>{{scope.row.balanceType === 0 ? '支出' : '收入'}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="passiveUserName"
        header-align="center"
        align="center"
        label="操作人账号">
      </el-table-column>
      <el-table-column
        prop="passiveTrueName"
        header-align="center"
        align="center"
        label="操作人名称">
      </el-table-column>
      <el-table-column
        prop="passiveUserType"
        header-align="center"
        align="center"
        label="用户类型">
        <template slot-scope="scope">
          <el-tag>{{scope.row.passiveUserType === 1 ? '运营商' : (scope.row.passiveUserType === 2 ? '联盟店' : (scope.row.passiveUserType === 3 ? '普通消费者' : (scope.row.passiveUserType === 4 ? 'VIP会员' : (scope.row.passiveUserType === 5 ? '普通联盟店' : (scope.row.passiveUserType === 6 ? '高级联盟店' : (scope.row.passiveUserType === 7 ? '城市合伙人' : (scope.row.passiveUserType === 8 ? '联盟店城市合伙人' : '')))))))}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="changeRemark"
        header-align="center"
        align="center"
        label="余额变动说明">
      </el-table-column>
      <el-table-column
        prop="changeBalance"
        header-align="center"
        align="center"
        label="变动金额">
        <template slot-scope="scope">
          <span v-if="scope.row.changeBalance != null">￥ {{scope.row.changeBalance}}</span>
          <span v-if="scope.row.changeBalance == null">￥ 0</span>
        </template>
      </el-table-column>
      <!--<el-table-column
        prop="logType"
        header-align="center"
        align="center"
        label="变动类型）">
        <template slot-scope="scope">
          <el-tag>{{scope.row.logType === 1 ? '已到账' : '即将到帐'}}</el-tag>
        </template>
      </el-table-column>-->
      <el-table-column
        prop="currentBalance"
        header-align="center"
        align="center"
        label="变动后的用户余额">
        <template slot-scope="scope">
          <span v-if="scope.row.currentBalance != null">￥ {{scope.row.currentBalance}}</span>
          <span v-if="scope.row.currentBalance == null">￥ 0</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.balanceId)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.balanceId)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './shoppingbalancelog-update'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          time: new Date()
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/balanceLog/queryAdminAndBalanceLog'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'lastStart': this.dataForm.time[0],
            'lastEnd': this.dataForm.time[1]
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init()
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.balanceId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/shoppingbalancelog/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
